/*
 * Virtual TouchScreen driver
 *
 * Copyright (C) 2011 Niu Tao <niutao0602@gmail.com>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License. See the file COPYING in the main directory of this archive for
 * more details.
 *
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/input.h>

#define DRIVER_DESC "Virtual TouchScree"

MODULE_AUTHOR("Niu Tao <niutao0602@gmail.com>");
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");

static struct input_dev *vts_dev;

#define VTS_MIN_XC 0
#define VTS_MAX_XC 640
#define VTS_MIN_YC 0
#define VTS_MAX_YC 480

static int __init vts_init(void)
{
	int err;

	vts_dev = input_allocate_device();
	if (!vts_dev) {
		printk(KERN_ERR "vts: not enough memory\n");
		err = -ENOMEM;
		goto fail1;
	}

	vts_dev->name = DRIVER_DESC;
	vts_dev->phys = "vts/input0";
	vts_dev->id.bustype = BUS_VIRTUAL;
	vts_dev->id.vendor  = 0x0000;
	vts_dev->id.product = 0x0000;
	vts_dev->id.version = 0x0100;

	vts_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
	vts_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
	input_set_abs_params(vts_dev, ABS_X, VTS_MIN_XC, VTS_MAX_XC, 0, 0);
	input_set_abs_params(vts_dev, ABS_Y, VTS_MIN_YC, VTS_MAX_YC, 0, 0);

	err = input_register_device(vts_dev);
	if (err)
		goto fail2;

	return 0;

 fail2:	
 fail1:	
    input_free_device(vts_dev);
	return err;
}

static void __exit vts_exit(void)
{
	input_unregister_device(vts_dev);
}

module_init(vts_init);
module_exit(vts_exit);
